<template>
	<view class="">
		<u-navbar :is-back="true" title="添加留言" back-icon-color="#ffffff" title-color="#ffffff"
			:background="{backgroundColor:'#E62131'}"></u-navbar>
		<view class="teltlfts" style="padding-right: 30rpx;">
			<u-input v-model="parms.leaveContent" :type="type" :border="border" :height="height"
				:auto-height="autoHeight" />
		</view>
		<view class=""
			style="display: flex;align-items: center;justify-content: flex-end;padding-right: 30rpx;">
			<u-upload :action="action" :header="header" :file-list="fileList" v-if="!form.id"
				@on-success="onsuccess"></u-upload>
		</view>
		<view class="bneads w-btn-fixed">
			<div class="btnlst fliexs space_between">
				<view class="btn_left right" @click="okllists">
					确定
				</view>
			</div>
		
		</view>
	</view>
</template>

<script>
	import staticUrl from "@/common/config.js"
export default {
		data() {
			return {
				
				action: staticUrl.staticUrl,
				header: {
					accessToken: 'bearer ' + uni.$func.cache("token"),
				},
				fileList: [],
				imglsit: [],
				autoHeight: true,
				type: 'textarea',
				border: true,
				height: 150,
				parms:{
					workId:"",
					studentId:"",
					leaveContent:"",
					leaveImg:"",
					leaveType:0,
					id:"",
				},
				form:{
					id:"",
					askUserContent:"",
				}
			}
		},
		onLoad(option) {
			if(option.type == 1){
				this.form.id = option.id
			}else{
				this.parms.workId = option.workId
				this.parms.studentId = option.studentId
				this.parms.id = option.id
				this.parms.leaveContent = option.leaveContent
				if(option.leaveImg){
					this.parms.leaveImg = option.leaveImg
					this.fileList.push({
						url:option.leaveImg
					})
				}
			}
			
		},
		methods: {
			onsuccess(e) {
				uni.showToast({
					title: "图片上传成功",
					icon: 'none'
				})
				this.parms.leaveImg = e.result.path
			},
			okllists(){
				if(this.form.id){
					this.form.askUserContent = this.parms.leaveContent
					uni.$api.common.studentaskaddConent(this.form).then((res) => {
						uni.showToast({
							title: "操作成功",
							icon: 'none'
						})
						setTimeout(() => {
							uni.navigateBack({
								delta: 1,
							})
						}, 2000)
					});
				}else{
					uni.$api.common.studentleaveaddLeave(this.parms).then((res) => {
						uni.showToast({
							title: "操作成功",
							icon: 'none'
						})
						setTimeout(() => {
							uni.navigateBack({
								delta: 1,
							})
						}, 2000)
					});
				}
			},
		}
	}
</script>

<style lang="scss">
	.teltlfts {
		padding: 30rpx;
		margin-bottom: 20rpx;
	
		.listta {
			line-height: 60rpx;
		}
	}
	.btnlst {
		// margin-top: 350rpx;
	
		.btn_left {
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			color: #b1b1b1;
			border: 1rpx solid #e1e1e1;
		}
	
		.right {
			background-color: #E62131;
			color: #ffffff;
		}
	}
</style>